package com.qibao.toolkit.exception;

import com.qibao.toolkit.exception.strategy.AbstractExceptionHandleStrategy;
import com.qibao.toolkit.exception.strategy.BaseExceptionHandleStrategyAware;
import com.qibao.toolkit.exception.strategy.ExceptionHandleType;
import com.qibao.toolkit.web.ResponseModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 处理业务异常信息
 *
 * @author wangcheng
 * @version $Id: BusinessExceptionHandlerStrategy.java, v0.1 2018/10/10 18:32 wangcheng Exp $$
 */
@ExceptionHandleType(BusinessException.class)
public class BusinessExceptionHandlerStrategy extends AbstractExceptionHandleStrategy implements
        BaseExceptionHandleStrategyAware {

    private static final Logger logger = LoggerFactory.getLogger(
            BusinessExceptionHandlerStrategy.class);

    @Override
    public ResponseModel<Boolean> doHandle(Throwable throwable) {
        BusinessException be = (BusinessException) throwable;
        //记录日志信息
        logger.warn(be.getLogInfo());
        return ResponseModel.ERROR(be.getMessage(), false);
    }
}
